package com.yb.core.config;

import cn.hutool.crypto.asymmetric.RSA;
import com.yb.core.util.YbFileReader;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;

import java.io.IOException;

@Configuration
@Slf4j
public class SecureConfig {

    ResourceLoader resourceLoader=new DefaultResourceLoader();
    @Bean
    public RSA rsaLogin() throws IOException {
        Resource privateResource = resourceLoader.getResource("classpath:login-private.txt");
        Resource publicResource = resourceLoader.getResource("classpath:login-public.txt");

        log.info("{}",privateResource);
        log.info("{}",publicResource);
        String privateKey = YbFileReader.readAsString(privateResource.getInputStream());
        String publicKey  = YbFileReader.readAsString(publicResource.getInputStream());
        log.info("private:{}",privateKey);
        log.info("public:{}",publicKey);
        return new RSA(privateKey,publicKey);
    }

}
